package com.uvlab.sitespot.io;

import java.util.HashMap;
import java.util.LinkedHashMap;

import com.uvlab.sitespot.service.JxAppService;
import com.uvlab.sitespot.service.user.JxUser;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("/rest/user")
public class JxUserController {

    @Resource
    JxAppService svc;

    @RequestMapping(method = RequestMethod.GET)
    public LinkedHashMap getUsers(){
        return  svc.getUserService().find();
    }

    @RequestMapping(method = RequestMethod.POST)
    public  void addusers(@RequestBody JxUser user){
        svc.getUserService().add(user);
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JxUser getUser(@PathVariable(value = "id")String id){
        return svc.getUserService().get(id);
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public void deleteuser(@PathVariable(value = "id")String id){
        svc.getUserService().remove(id);
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.PUT)
    public void updateuser(@PathVariable(value = "id")String id,@RequestBody JxUser user){
        svc.getUserService().set(id,user);
    }
}
